# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :send_code.py
# @Time      :2022/5/27 16:52
# @Author    :张志坤
from ronglian_sms_sdk import SmsSDK
from common.celery_tasks.main import app
import redis, json


@app.task
def sms_code(mobile, code, expire=5):
    sdk = SmsSDK(
        accId="8a216da8804ba8a5018064a0d4520669",
        accToken="b1b59ee7bbdd4f37b240c67dc77a0540",
        appId="8a216da8804ba8a5018064a0d5470670"
    )
    tid = "1"
    mobile = "%s" % mobile
    datas = ("%s" % code, "%s" % expire)
    res = sdk.sendMessage(tid, mobile, datas)
    # 连接redis
    redis_cli = redis.Redis(host="127.0.0.1", port=6379, db=3)
    print("这是啥>?>>>>?>", json.loads(res)['statusCode'])
    if json.loads(res)['statusCode'] == "000000":
        redis_cli.set(mobile, code, ex=30000)
        redis_cli.close()
        return True
    return False
